package com.example.yingjiguanli_demo.controller;

import com.example.yingjiguanli_demo.aspect.interfaces.RateLimiter;
import com.example.yingjiguanli_demo.aspect.interfaces.RequirePermission;
import com.example.yingjiguanli_demo.pojo.Announcements;
import com.example.yingjiguanli_demo.pojo.Result;
import com.example.yingjiguanli_demo.service.IAnnouncementsService;
import com.example.yingjiguanli_demo.service.impl.AnnouncementsServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author scj
 * @since 2024-11-13
 */
@RestController
@RequestMapping("/v1/announcements")
public class AnnouncementsController {
    @Autowired
    private IAnnouncementsService announcementsService;

    /***
     * 添加公告
     * @param announcements 公告
     * @return Result<T>
     */
    @ApiOperation(value = "添加公告")
    @RequirePermission("admin")
    @RateLimiter
    @PostMapping("/add")
    public Result<T> addAnnouncement(@RequestBody Announcements announcements) {
        return announcementsService.add(announcements);
    }
    @ApiOperation(value = "获取最新公告")
    @RequirePermission("user")
    @GetMapping("/get")
    public Result<Announcements> get() {
        return announcementsService.get();
    }



}
